package ilearn.job.disserver.acconut.service;

import ilearn.job.disserver.acconut.entity.Account;
import ilearn.job.disserver.acconut.repository.AccountRepository;
import ilearn.job.disserver.sdk.account.dto.AccountDTO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AccountService {
    @Resource
    private AccountRepository accountRepository;
    private static final Account NanAccount = Account.builder().id(0L).name("NanAccount").build();

    public Account getAccountById(Long id){
        return accountRepository.findById(id).orElse(NanAccount);
    }

    public Account putAccount(AccountDTO accountDTO){
        Account account = new Account();
        account.fromAccountDTO(accountDTO);
        account = accountRepository.save(account);
        return account;
    }
}
